//标题长度处理
import da from "element-ui/src/locale/lang/da";

export const sliceStr = (text, len) => {
    if (!text || !len) {
        return ''
    }
    let stext = text.slice(0, len)
    if (text.length > len) {
        stext += '...'
    }
    return stext
}
//倒计时计算
export const dTime = (time) => {
    if (!time) {
        return ''
    }
    let timeNum = (new Date(time.replace(/-/g, "/")).getTime() - new Date().getTime()) / 1000

    if (timeNum > 0) {
        return Number(timeNum.toFixed(0))
    } else {
        return 0
    }
}
//正计时计算
export const zTime = (time, type) => {
    //n-年 y-月 r-日 s-时 f-分 m-秒
    if (!time) {
        return ''
    }
    let date = ''
    switch (type) {
        case 'n':
            date = new Date(new Date().getTime() + time * 365 * 24 * 3600 * 1000);
            break;
        case 'y':
            date = new Date(new Date().getTime() + time * 30 * 24 * 3600 * 1000);
            break;
        case 'r':
            date = new Date(new Date().getTime() + time * 24 * 3600 * 1000);
            break;
        case 's':
            date = new Date(new Date().getTime() + time * 3600 * 1000);
            break;
        case 'f':
            date = new Date(new Date().getTime() + time * 60 * 1000);
            break;
        case 'm':
            date = new Date(new Date().getTime() + time * 1000);
            break;

    }
    let y = date.getFullYear();
    let m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    let h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    let minute = date.getMinutes();
    let second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    //最终时间dates
    let dates = y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
    console.log(dates, "多少时间后")

}
export const onBreak = (index, data) => {
    if (!data) {
        this.$router.go(-1)
    } else {
        localStorage.setItem('onbreak', data)
    }

}
//判断是否不为空
export const noNull = (data) => {
    if(Array.isArray(data)){
        if(data.length>0){
            return true;
        }else {
            return false;
        }
    }
    switch (data) {
        case null:
            return false;
        case '':
            return false;
        case {}:
            return false;
        case undefined:
            return false;
        default :
            return true;
    }
}
//去空
export const wipeOutn = (data) => {
    return  data.replace(/\s/g,"")
}
